#include <yas/serialize.hpp>
#include <yas/std_types.hpp>
#undef NDEBUG
#include <cassert>


/***************************************************************************/
struct type
{
  type()
      : i(0xff), u(44)
  {
  }

  std::uint32_t i;
  std::uint64_t u;

  template <typename Ar>
  void serialize(Ar &ar)
  {
    ar &YAS_OBJECT("type", yas::init(i), u);
  }
};

/***************************************************************************/
int main()
{
  int a = 3, aa{};
  short b = 4, bb{};
  float c = 3.14, cc{};

  constexpr std::size_t flags =
      yas::mem     // IO type
      | yas::json; // IO format

  auto buf = yas::save<flags>(
      YAS_OBJECT("myobject", a, b, c));

  // buf = {"a":3,"b":4,"c":3.14}

  yas::load<flags>(buf,
                   YAS_OBJECT_NVP("myobject", ("a", aa), ("b", bb), ("c", cc)));
  // a == aa && b == bb && c == cc;

  {
    type t1, t2;
    t2.i = 0xffffffff;
    t2.u = 0;

    constexpr std::size_t flags = yas::mem | yas::binary | yas::compacted;
    auto buf = yas::save<flags>(t1);
    yas::load<flags>(buf, t2);

    assert(t1.i == t2.i && t1.u == t2.u);
  }
}
